<template>
  <div>
    <el-dialog
      :title="statesMap[row.status === 0 ? 1 : 0 ]"
      :visible="isShow"
      width="30%"
      @close="closeBtn"
    >
      <span>确定要{{ statesMap[row.status === 0 ? 1 : 0 ] }}库区：{{ row.name }}吗</span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="closeBtn">取 消</el-button>
        <el-button type="warning" @click="changeFn">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { openApi } from '@/api'
export default {
  props: {
    form: {
      type: Object,
      default: () => {}
    },
    isShow: {
      type: Boolean,
      default: false
    },
    row: {
      type: Object,
      default: () => {}
    }
  },
  data() {
    return {
      statesMap: {
        0: '停用',
        1: '启用'
      }
    }
  },
  methods: {
    // 关闭dialog
    closeBtn() {
      this.$emit('closeBtn')
    },
    // 改变启用
    async changeFn() {
      this.row.status === 0 ? this.row.status = 1 : this.row.status = 0
      await openApi({ id: this.row.id, status: this.row.status })
      this.closeBtn()
      this.$message.success('更新状态成功')
      this.$emit('publicFn', this.form)
    }
  }
}
</script>

<style>

</style>
